﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YY.UI.BaseDataSvc;
using YY.Common;

namespace YY.UI
{
    public partial class ResetPwdFrm : BaseFrm
    {
        public ResetPwdFrm()
        {
            InitializeComponent();
            this.BaseDataProxy = new YY.UI.BaseDataSvc.BaseDataClient();
        }

        private void ResetPwdFrm_Load(object sender, EventArgs e)
        {
            this.BaseDataProxy.Open();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            TB_User user = this.BaseDataProxy.GetUser(SysLoginUserInfo.UserId);
            if (user != null)
            {
                string oPwd = string.IsNullOrEmpty(this.txtBoxOPwd.Text) ? null : EncryptCommon.MD5Encrypt(this.txtBoxOPwd.Text);
                if (oPwd != user.pwd)
                {
                    MessageBox.Show("原密码输入不正确！");
                    return;
                }
                string nPwd = string.IsNullOrEmpty(this.txtBoxNPwd.Text) ? null : EncryptCommon.MD5Encrypt(this.txtBoxNPwd.Text);
                user.pwd = nPwd;

                if (this.BaseDataProxy.UpdateUser(user))
                    MessageBox.Show("密码重置成功！");
                else
                    MessageBox.Show("密码重置异常！");
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
